While negotiations for a Namibian independence agreement are focused on U.S. attempts to get Cuban troops out of neighboring Angola, one contentious factor that has become obscured is South Africa's intention to keep possession of the territory's only seaport.

Walvis Bay is situated almost dead-center along 1,000 miles of Namibia's desert coastline. There is no possibility of building a port anywhere else.

By keeping Walvis Bay, South Africa could ensure that a future independent Namibia is totally dependent on it economically.

The only other outlet is by railroad into South Arica -- and even the railroad is owned by the nationalized South African Railways.

When South Africa first claimed legal ownership of Walvis Bay at the start of the Western-initiated negotiations in 1977, objections were raised by the black nationalist South-West African People's Organization (SWAPO), which likely would form the government of an independent Namibia.

The matter has not been raised again since the Reagan administration revived the search for a settlement last year. The South Africans contend that the validity of their claim has been accepted by Washington.

They stressed their point earlier this month when for the first time they constituted Walvis Bay as a parliamentary constituency and let it elect its own representative to the South African parliament in Cape Town.

Prime Minister Pieter W. Botha traveled to the port for the special election and pledged in a campaign speech there Sept. 24 that it would never become part of Namibia.

South Africa would be prepared to negotiate the port's use with a friendly government after Namibia becomes independent, said Botha, raising the intriguing question of what it would do in the case of a SWAPO government.

Botha and his ministers make no secret of their hostility toward SWAPO, which they regard as Communist.

Historically South Africa's claim seems strong. Britain occupied a 385-square mile enclave around Walvis Bay in 1878 in an attempt to block Bismarck's moves toward colonizing what was then called South- West Africa.

The attempt failed, although Britain retained Walvis Bay. Bismarck formed his colony five years later and sent Hermann Goering's father out as its first imperial commissioner. A year after that Britain passed its annexation over to the government of Cape Colony, which in 1910 became part of present-day South Africa.

During World War I South Africa occupied the German colony and was afterwards granted a League of Nations mandate to administer it. For more than half a century it ran the whole territory, Walvis Bay included, as though it were part of South Africa--which the Pretoria government fully intended it to become.

Only growing world pressure for Namibia's independence has finally forced it to drop that intention.

"I don't think anyone here had any idea Walvis had a separate status [as part of the British annexation given to South Africa]," said Mayor Nico Retief. "But now we are all pleased about it. It gives us a sense of security knowing South Africa has this strong bargaining point."

Although it may have meant security for some it has meant a degree of confusion for others, because a different set of laws now applies in Walvis Bay from the rest of Namibia.

When South Africa imposed direct rule in 1977 it introduced all its own apartheid, or strict segregationist, laws at a time when it was allowing the internal administration in the rest of Namibia to try to impress the world by abolishing them there.

Vernon Webster, chairman of the property owners association, is one who fell foul of the confusion. With the advent of direct rule he was prosecuted for allowing mixed-race Colored tenants to occupy an apartment block he owned.

This is a crime under South African law, but not in Namibia. Furious, Webster chose to serve a five-day prison term rather than pay a fine.

What made the case even more noteworthy is that Walvis Bay had no jail at the time (one is being built now), so Webster had to be taken to Swakopmund 22 miles away and outside the enclave.

"I must be the first person to have served a prison sentence in a place where what I had done was not a crime," he remarked.

Webster's experience is not the only legal absurdity that has arisen. Most local whites are happy enough to have South Africa's apartheid laws imposed, but not its stringent liquor laws. They had grown accustomed to the continental ways of the former German colony, so by popular demand the liquor laws were waived and the pubs still open on Sundays.

So, it seems, have the South African laws prohibiting marriages and sex across the color line. At Natasha's night club on the waterfront black prostitutes pick up white sailors without apparent anxiety.

Heinz Peveling, a German watch repairer, and his Colored wife Rachel have a house in town and there has been no attempt to prosecute them.

At first the Pevelings were so worried about the South African laws that they took a house in Swakopmund and drove to work every day, but a year ago they decided the 44-mile round trip was too expensive and they moved to Walvis Bay.

"We just said to hell with it, let's go and see what happens," said Rachel. "Well, nothing has happened yet, but we haven't been able to get our little girl into a nursery school. We'll have to send her away next year."

"It's completely arbitrary," says Webster. "They switch these laws on and off to suit themselves."

Walvis Bay is an unlovely town in a dramatic setting. The Namib Desert sweeps in great red dunes into an icy South Atlantic, where the Benguella current washes up from Antarctica.

The combination of cold sea and burning desert has produced the most desolate coastline on earth. The moonscape of the Skeleton Coast stretches away to the Angolan border in the north, a legendary wasteland which was the graveyard of early navigators trying to find a route to the East.

The desert sand sifts into the town pervasively. The heat is like fire. Walvis Bay is a fishing port and during the season the stench of fishmeal from waterfront factories fills the air.

The buildings are low, squat, lacking even in functional beauty. The style is garish utilitarian, gas-station gothic. There are bars and liquor stores on every block. Huge silver fuel storage tanks spill into town, reflecting the solar heat like mirrors.

It used to be a prosperous place with one of the world's richest fishing grounds just off the coast, but South African fishermen plundered it. Excessive catches have depleted the waters, and damage to the pelagic fish resources may be irreversible. A pilchard catch of 1,387,000 tons in 1968 had dwindled to 11,000 tons by 1980.

The population of Walvis Bay has shrunk as a result, from 30,000 to 22,000, according to town clerk Jan J. Wilken.

But Wilken thinks boom times may come back to Walvis Bay if Namibia becomes independent. Anxious whites, he believes, will use it has a bolthole. He says they are buying up property already.